<template>
    <div class="app-container">
        <!-- 查询模块 -->
        <div class="formDiv">
            <el-form ref="form" :inline="true" :model="form" label-width="130px">
                <el-row>
                    <el-col :span="6">
                        <el-form-item label="订单号">
                            <el-input v-model="form.username"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="姓名">
                            <el-input v-model="form.nickName"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="手机号">
                            <el-input v-model="form.realName"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="医院名称">
                            <el-input v-model="form.refereePhone"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="项目名称">
                            <el-input v-model="form.refereePhone"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="项目分类">
                            <el-input v-model="form.refereePhone"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="订单状态">
                            <el-input v-model="form.refereePhone"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="订单下单时间" width="236">
                            <el-date-picker
                                value-format="yyyy-MM-dd HH:mm:ss"
                                v-model="dates"
                                type="daterange"
                                range-separator="-"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="订单支付时间" width="236">
                            <el-date-picker
                                value-format="yyyy-MM-dd HH:mm:ss"
                                v-model="dates"
                                type="daterange"
                                range-separator="-"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item>
                            <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <!-- 主页列表 -->
        <div class="listDiv" v-loading="tableLoading">
            <!-- table列表 -->
            <el-table
                :data="tableData"
                style="width: 100%">
                <el-table-column
                    fixed
                    prop="userId"
                    label="订单号"
                >
                </el-table-column>
                <el-table-column
                    prop="nickName"
                    label="用户姓名"
                >
                </el-table-column>
                <el-table-column
                    prop="realname"
                    label="手机号"
                >
                </el-table-column>
                <el-table-column
                    prop="username"
                    label="医院名称"
                    width="120"
                >
                </el-table-column>
                <el-table-column
                    label="项目名称"
                >
                    <template slot-scope="scope">
                        {{scope.row.identityType | cardType}}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="identity"
                    label="订单应付金额"
                >
                </el-table-column>
                <el-table-column
                    prop="refereeName"
                    label="支付方式"
                >
                </el-table-column>
                <el-table-column
                    prop="referee"
                    label="订单状态"
                    width="120"
                >
                </el-table-column>
                <el-table-column
                    prop="createdAt"
                    label="下单时间"
                >
                </el-table-column>
                <el-table-column
                    prop="createdAt"
                    label="支付时间"
                >
                </el-table-column>
                <el-table-column
                    prop="createdAt"
                    label="退款时间"
                >
                </el-table-column>
                <el-table-column
                    prop="createdAt"
                    label="退款说明"
                >
                </el-table-column>
                <el-table-column
                    fixed="right"
                    label="操作"
                    width="100"
                >
                    <template slot-scope="scope">
                        <el-button type="text" @click="toRoutes('itemOrderInfo',scope.row.id)" size="small">详情</el-button>
                        <el-button type="text" @click="refundFn(scope.row.id)" size="small">退款</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 退款说明 -->
            <el-dialog
                title="请填写退款说明(必填)"
                :visible.sync="dialogVisible"
                :before-close="handleClose"
                width="468px">
                <!-- 输入框 -->
                <el-form :inline="true"
                label-width="80px"
                label-position="right"
                >
                    <el-input
                        type="textarea"
                        :rows="6"
                        placeholder="请输入内容">
                    </el-input>
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="handleClose()">取 消</el-button>
                    <el-button type="primary" @click="addSubmit()">确 定</el-button>
                </span>
            </el-dialog>
            <!-- 分页 -->
            <div class="pagesCon">
                <div>
                    <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="listForm.pageNum"
                    :page-sizes="page_sizes"
                    :page-size="listForm.limit"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="page_totals">
                    </el-pagination>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
// updateStatus
    import { findProjectOrderList} from '@/api/itemOrder'
    export default {
        name:"itemOrderIndex",
        data() {
            return {
                dialogVisible:false,
                tableLoading:true,
                dates:[],
                form: {
                    username: '',
                    nickName: '',
                    realName: '',
                    refereePhone: '',
                    status: "",
                    createdAtStart:'',
                    createdAtEnd:'',
                    pageNum:1,
                    pageSize:10,
                },
                tableData: [],
                page_sizes:[10,30,50,100],
                page_totals:60,
                listForm:{
                    pageNum:1,
                    pageSize:10,
                },
            }
        },
        filters:{
            cardType: function(e){
                return window.helper.cardType(String(e))
            },
        },
        mounted(){
            this.getList(this.listForm)
        },
        methods: {
            //关闭弹窗
            handleClose(){
                this.dialogVisible = false
                // this.$refs["addForm1"].resetFields();
            },
            addSubmit(){
                console.log("提交了")
                this.dialogVisible = false
            },
            //成功状态弹窗
            succStatus(txt){
                this.$message({
                    message: txt+'成功',
                    type: 'success'
                });
            },
            //失败状态弹窗
            errorStatus(txt){
                this.$message.error(txt+'失败');
            },
            //列表数据获取
            getList(e){
                this.tableLoading = true
                let datas = e
                findProjectOrderList(datas).then(res => {
                    console.log(res)
                    if(!res.data.code){
                        // console.log(res)
                        this.tableData = res.data.data
                        this.page_totals = res.data.data.count
                    }else{
                        this.$message.error("数据接口访问失败");
                    }
                    this.tableLoading = false
                })
                .catch(error =>{
                    this.$message.error(error);
                })
            },
            // 查询
            searchFn() {
                if(this.dates!=null){
                    if(this.dates.length){
                        this.form.createdAtStart = this.dates[0];
                        this.form.createdAtEnd = this.dates[1];
                        this.getList(this.form)
                    }else{
                        this.getList(this.form)
                    }
                }else{
                    this.form.createdAtStart = "";
                    this.form.createdAtEnd = "";
                    this.getList(this.form)
                }
                // console.log(JSON.stringify(this.form))
            },
            //账号状态修改
            refundFn(e){
                console.log(e)
                this.dialogVisible = true
            },
            // 路由跳转
            toRoutes(e,userId) {
                let route = {name:e,query:{userId:userId}}
                this.$router.push(route)
            },
            //改变页面条数
            handleSizeChange(val) {
                this.form.pageSize = val
                this.getList(this.form)
            },
            //选择页数
            handleCurrentChange(val) {
                this.form.pageNum = val
                this.getList(this.form)
            }
        }
    }
</script>
<style scoped>
/* 分页 */
.pagesCon{height: 40px;margin-top: 20px}
.pagesCon>div{float: right;}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner{width: 236px}
</style>
